// pages/emotion/emotion.js
const app = getApp()
import {getDeskList,getCategory} from '../../service/config/index'
import {BUS_STATUS,BUS_Category} from '../../service/config/constant.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    titles:[],
    list:[],
    baseUrl:app.globalData.url,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    let param = {}
    param.status = BUS_STATUS.Enable  
    this._getCategory()
    this._getDeskList(param)
  },

  tabclick(e){
    let index = e.detail.index
    let titleId = this.data.titles[index].id
    let param = {}
    param.status = BUS_STATUS.Enable  
    param.cateId = titleId
    this._getDeskList(param)
  },

  _getDeskList(param){
    let that = this
    getDeskList(param).then(res=>{
      if(res.code == 200){
        that.setData({
          list:res.rows
        })
      }
    })
  },  

  // 获取Tag数据
  _getCategory(){
    let that = this;
    let param = {}
    param.type = BUS_Category.TYPE_EMO
    param.status = BUS_STATUS.Enable  
    getCategory(param).then(res=>{
      let nav = res.rows
      nav.unshift({id:0,name:"全部"})
      that.setData({
        titles:nav,
        currentIndex:nav[0].id
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log('执行分页')
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})